package pub.tbc.toolkit.http;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import pub.tbc.toolkit.Objs;

import java.util.Map;

/**
 * @author tbc tianbencai@e-eduspace.com
 * @version 1.0 {2016年3月25日 下午1:13:40}
 */
public class MyResponse {

    private int code;
    private int httpCode;
    private String msg;
    private String response;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public int getHttpCode() {
        return httpCode;
    }

    public void setHttpCode(int httpCode) {
        this.httpCode = httpCode;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getResponse() {
        return response;
    }

    public void setResponse(String response) {
        this.response = response;
    }

    /**
     * 将请求的返回结果转为Map<br>
     * 注： 当返回值为JSON时用，此处不做校验，自己控制
     *
     * @return
     * @author tbc tianbencai@e-eduspace.com
     * @version 1.0 {2016年3月31日 上午9:34:27}
     */
    public Map<String, Object> toMap() {
        return new Gson().fromJson(this.response, new TypeToken<Map<String, Object>>() {
        }.getType());
    }

    public Map<String, Object> getWrapperResult() {
        Map<String, Object> map = toMap();
        @SuppressWarnings("unchecked")
        Map<String, Object> result = (Map<String, Object>) map.get("result");
        if (Objs.nonEmpty(result)) {

        }
        return result;
    }

}
